package cz.muni.fi.pa165.rentalofconstructionmachinery.dto.converters;

import cz.muni.fi.pa165.rentalofconstructionmachinery.dto.RevisionDTO;
import cz.muni.fi.pa165.rentalofconstructionmachinery.entity.Revision;

/**
 *
 * @author Adam Zmrzlý
 * @version Miura (20121101)
 */
public class RevisionDTOConverter {

    /*
     * Converts RevisionDTO to a Revision entity.
     * @param dto DTO to convert.
     * @return Revision entity according to the DTO. If dto is null, returns null.
     */
    public static Revision dtoToEntity(RevisionDTO dto) {

        if(dto == null) return null;

        Revision revision = new Revision();

        revision.setId(dto.getId());
        revision.setDate(dto.getDate());
        revision.setMachine(MachineDTOConverter.dtoToEntity(dto.getMachine()));
        revision.setComment(dto.getComment());

        return revision;
    }

    /*
     * Converts Revision entity to a RevisionDTO.
     * @param revision Entity to convert.
     * @return RevisionDTO according to the entity. If revision is null, returns null.
     */
    public static RevisionDTO entityToDTO(Revision revision) {

        if(revision == null) return null;

        RevisionDTO revisionDTO = new RevisionDTO(revision.getId(),
                MachineDTOConverter.entityToDTO(revision.getMachine()), revision.getDate(), revision.getComment());

        return revisionDTO;
    }
}
